import React from "react";
import { Button, List, Form, Input, DatePicker, Select, Switch, Radio, InputNumber, Space, Modal } from 'antd';
import Goods from './components/goods'
import { apiPlatformActivitySheetEdit, apiPlatformActivitySheetView, apiGetActivityConfig, apiActivitySkuRepetitionVerify, apiActivitySkuFloorPriceVerify } from '@/request/activityManager'
import GoBack from '@/components/TheGoBack'
import NoCanJoinGood from './components/noCanJoinGood'

import TheUpload from '@/components/TheUpload'
import Coupons from './components/coupons'
import { MinusCircleOutlined, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons';
import './components/style.less'
import moment from 'moment'
import dayjs from 'dayjs'

const { RangePicker } = DatePicker;
const { TextArea } = Input
const { confirm } = Modal;

class ActivityEdit extends React.Component {
    constructor() {
        super()
        this.formRef = React.createRef()
        this.state = {
            coupons: [],
            couponsCopy: [],
            sights: [],
            optionType: [{ label: '优惠商品', value: 'SHOP_GOODS' }, { label: '新人活动', value: 'NEW_COME' }],
            // activeTimes: [],
            activityId: '',
            optionWay: [],
            activeTimes: [],
            options: [{
                label: '短期',
                value: 1
            }, {
                label: '长期',
                value: 2
            }],
            goodsSku: [],
            couponEnabled: 0,
            timeType: 1,
            goodsFlag: true,
            checkIng: false,
            activityImg: [],
            activityLabelImg: [],
            detailImg: [],
            levelOption: [{ label: 'S', value: 'S' },
            { label: 'A', value: 'A' },
            { label: 'B', value: 'B' },
            { label: 'C', value: 'C' }],
            whiteGoodsKey: [],
            blackGoodsKey: [],
            blackGoods: [],
            visible: false,
            saveData: {},
            clashData: []
        }
    }
    formRef = React.createRef()
    PromotionsBox = React.createRef()
    async componentDidMount() {
        this.getConfigTypes('ACTIVITY_TYPE')
        this.getConfigTypes('ACTIVITY_WAY')
        await this.getInfo(this.props.match.params.id)
    }
    async getConfigTypes(platformSetKey) {
        const res = await apiGetActivityConfig({ platformSetKey })
        if (res.code === 0) {
            if (platformSetKey === 'ACTIVITY_TYPE') {
                this.setState({
                    optionType: res.data.map(item => {
                        return {
                            label: item.platformSetShowValue,
                            value: item.platformSetUseValue
                        }
                    })
                })
            } else {
                this.setState({
                    optionWay: res.data.map(item => {
                        return {
                            label: item.platformSetShowValue,
                            value: item.platformSetUseValue
                        }
                    })
                })
            }

        }
    }
    async getInfo(activityId) {
        const res = await apiPlatformActivitySheetView({ activityId })
        if (res.code === 0 && res.data) {
            let data = res.data
            let goodsSku = [], coupons = [], sights = []
            // 满减活动黑名单商品
            let blackGoodsKey = [], blackGoods = [], whiteGoodsKey = []
            if (['FULL_REDUCTION'].includes(data.activityType)) {
                data.activityBlacklists.forEach(item => {
                    blackGoodsKey.push(item.goodsId)
                    blackGoods.push({ ...item.goodsInfo })
                })
            }
            if (['COUPONS'].includes(data.activityType)) {
                data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                        coupons.push({
                            ...item,
                            couponTitle: item.activityDetailName,
                            couponType: item.prizeType,
                            couponId: item.prizeId
                        })
                    }
                })
            } else if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(data.activityType)) {
                data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                        let goodsVos = []
                        item.activityGoodsVos.forEach(goods => {
                            if (goods.activityGoodsId !== null) {
                                whiteGoodsKey.push(goods.goodsId)
                                goodsVos.push({
                                    activityDetailId: item.activityDetailId,
                                    activityId: item.activityId,
                                    activityPrice: goods.activityPrice,
                                    goodsId: goods.goodsId,
                                    storeId: goods.storeId,
                                    activityGoodsId: goods.activityGoodsId,
                                    storeName: goods.storeName,
                                    goodsName: goods.goodsName,
                                    Promotions: item.activityDetailName,
                                    missGoods: goods.goodsStatus === '0' ? false : true,
                                    hasJoinSku: true,
                                    skuInfoVos: goods.activityGoodsSkuVos.map(sku => {
                                        return {
                                            flag: true,
                                            missSku: sku.skuStatus === '0' ? false : true,
                                            skuAttributes: JSON.parse(sku.skuAttributes),
                                            "goodsId": sku.goodsId,
                                            "goodsSkuId": sku.goodsSkuId,
                                            "activityPrice": sku.missSku ? 0 : sku.activityGoodsSkuPrice === null ? null : (Number(sku.activityGoodsSkuPrice) / 100).toFixed(2),
                                            skuOriginalPrice: Number(sku.skuOriginalPrice),
                                            skuCurrentPrice: Number(sku.skuCurrentPrice),
                                            activityGoodsSkuId: sku.activityGoodsSkuId,
                                            activityGoodsId: sku.activityGoodsId,
                                            aliasName: data.activityType === 'FULL_GIFT' ? sku.aliasName : '',
                                            aliasFlag: true,
                                            isJoinFlag: sku.skuEnabled
                                        }
                                    })
                                })
                            }
                        })
                        goodsSku.push([item.activityDetailName, goodsVos, item.thresholdPrice ? (Number(item.thresholdPrice) / 100).toFixed(2) : null, true, item.activityDetailId])
                    }
                })
            } else if (['FULL_REDUCTION'].includes(data.activityType)) {
                data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                        sights.push({
                            ...item,
                            thresholdPrice: (Number(item.thresholdPrice) / 100).toFixed(2),
                            discountPrice: (Number(item.discountPrice) / 100).toFixed(2),
                        })
                    }
                })
            }
            this.setState({
                activityId,
                goodsSku,
                coupons,
                sights,
                whiteGoodsKey,
                blackGoodsKey,
                blackGoods,
                couponsCopy: coupons,
                couponEnabled: data.couponEnabled === 0,
                timeType: data.timeType === '1',
                detailImg: data.detailImg ? data.detailImg.split(',').map(v => {
                    return {
                        uid: new Date().getTime(),
                        name: 'image',
                        status: 'done',
                        url: v
                    }
                }) : [],
                activityImg: data.activityImg ? data.activityImg.split(',').map(v => {
                    return {
                        uid: new Date().getTime(),
                        name: 'image',
                        status: 'done',
                        url: v
                    }
                }) : [],
                // activityLabelImg: data.activityLabelImg ? data.activityLabelImg.split(',').map(v => {
                //     return {
                //         uid: new Date().getTime(),
                //         name: 'image',
                //         status: 'done',
                //         url: v
                //     }
                // }) : []
            }, () => {
                this.formRef.current.setFieldsValue({
                    activityName: data.activityName,
                    activityWay: data.activityWay,
                    coupons: coupons,
                    activityImg: data.activityImg,
                    blackGoods: blackGoodsKey,
                    // activityLabelImg: data.activityLabelImg,
                    detailImg: data.detailImg,
                    activityTime: data.startTime ? [moment(data.startTime), moment(data.endTime)] : [],
                    activityLevel: data.activityLevel,
                    detailExplain: data.detailExplain,
                    activityType: data.activityType,
                    goodsSku: goodsSku,
                    sights: sights.map((item, index) => {
                        return {
                            fieldKey: index,
                            isListField: true,
                            key: index,
                            name: index,
                            thresholdPrice: item.thresholdPrice,
                            discountPrice: item.discountPrice,
                            activityDetailId: item.activityDetailId,
                        }
                    }),
                    couponEnabled: data.couponEnabled === 0,
                    timeType: data.timeType === '1'
                })
            })
        }
    }
    async onFinish(values) {
        let submitData = async (params) => {
            let result = await apiActivitySkuRepetitionVerify(params)
            if (result.code === 0 && (result.data !== null && result.data.length > 0)) {
                this.setState({
                    clashData: result.data,
                    visible: true,
                    saveData: params
                })
            } else if (result.code === 0 && (result.data === null || result.data.length === 0)) {
                let res = await apiPlatformActivitySheetEdit(params)
                if (res.code === 0 && res.data) {
                    this.props.history.go(-1)
                }
            }
        }
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType) && !this.state.goodsFlag) return
        values.goodsSku = this.state.goodsSku
        let activityDetailVos = []
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType)) {
            activityDetailVos = values.goodsSku.map((item, activeIndex) => {
                return {
                    activityDetailId: item[1].length > 0 ? item[4] : '',
                    activityGoodsVos: item[1].map((goods, ii) => {
                        return {
                            activityDetailId: item[1].length > 0 ? item[4] : '',
                            activityGoodsId: goods.activityGoodsId,
                            activityGoodsSkuVos: goods.skuInfoVos.map(sku => {
                                sku.isJoinFlag = true
                                return {
                                    "goodsId": goods.goodsId,
                                    "goodsSkuId": sku.goodsSkuId,
                                    "activityGoodsSkuPrice": !sku.isJoinFlag ? sku.skuCurrentPrice : sku.activityPrice === null ? sku.skuCurrentPrice : Number((Number(sku.activityPrice) * 100).toFixed(0)),
                                    currentPrice: sku.currentPrice,
                                    activityGoodsSkuOriginalPrice: sku.skuOriginalPrice,
                                    activityGoodsSkuId: sku.hasOwnProperty('activityGoodsSkuId') ? sku.activityGoodsSkuId : '',
                                    activityGoodsId: sku.hasOwnProperty('activityGoodsId') ? sku.activityGoodsId : '',
                                    skuAttributes: JSON.stringify(sku.skuAttributes),
                                    aliasName: sku.aliasName,
                                    skuEnabled: sku.isJoinFlag ? 1 : 0
                                }
                            }),
                            sort: ii + 1,
                            "goodsId": goods.goodsId,
                            storeId: goods.storeId
                        }
                    }),
                    "activityDetailName": item[0],

                    "prizeType": "goods",
                    "activityName": values.activityName,
                    sort: activeIndex + 1,
                    thresholdPrice: values.activityType === 'FULL_GIFT' ? Number((Number(item[2]) * 100).toFixed(0)) : 0

                }
            })
        } else if (['COUPONS'].includes(values.activityType)) {
            activityDetailVos = values.coupons.map((item, index) => {
                const ii = this.state.couponsCopy.findIndex(ii => ii.couponId === item.couponId)
                return {
                    activityDetailName: item.couponTitle,
                    "prizeType": item.couponType,
                    sort: index + 1,
                    prizeId: item.couponId,
                    activityDetailId: ii > -1 ? this.state.couponsCopy[ii].activityDetailId : '',

                }
            })
        } else if (['FULL_REDUCTION'].includes(values.activityType)) {
            activityDetailVos = values.sights.map((item, index) => {
                const ii = this.state.sights.findIndex(ii => (item.hasOwnProperty('activityDetailId') && ii.activityDetailId === item.activityDetailId))
                return {
                    sort: index + 1,
                    "thresholdPrice": Number((Number(item.thresholdPrice) * 100).toFixed(0)),
                    "discountPrice": Number((Number(item.discountPrice) * 100).toFixed(0)),
                    prizeType: values.activityType,
                    activityDetailId: ii > -1 ? this.state.sights[ii].activityDetailId : null
                }
            })
        }
        let params = {
            // activityLabelImg: values.activityLabelImg,
            activityImg: values.activityImg,
            activityId: this.state.activityId,
            "activityName": values.activityName,
            "activityCount": -1, //活动数量 （ -1 为 无限量 ）
            "couponEnabled": values.couponEnabled ? 0 : 1, //能否使用优惠券 0 可以使用 1 不能使用
            "activityStatus": 1, //活动状态（0：正常 1：关闭）
            "activityType": values.activityType, //活动类型 （COUPONS 优惠卷 SHOP_GOODS 商城商品）
            activityDetailVos,
            detailExplain: values.detailExplain,
            detailImg: values.detailImg,
            startTime: values.timeType ? moment(values.activityTime[0]).format('yyyy-MM-DD HH:mm:ss') : '',
            endTime: values.timeType ? moment(values.activityTime[1]).format('yyyy-MM-DD HH:mm:ss') : '',
            timeType: values.timeType ? '1' : '0',
        }
        if (values.activityType === 'COUPONS') {
            params["activityWay"] = values.activityWay //活动方式（ REGISTERED 注册 ONSALE 特价）
        }
        if (['FULL_REDUCTION'].includes(values.activityType)) {
            params["activityBlacklists"] = values.blackGoods.map(item => {
                return { goodsId: item }
            }) //活动方式（ REGISTERED 注册 ONSALE 特价）
        }
        if (['SHOP_GOODS', 'NEW_COME'].includes(values.activityType)) {
            apiActivitySkuFloorPriceVerify(params).then(res => {
                if (res.code === 0 && res.data && Array.isArray(res.data) && res.data.length > 0) {
                    confirm({
                        title: '提示',
                        width: 800,
                        icon: <ExclamationCircleFilled />,
                        okText:'继续提交',
                        cancelText:"返回",
                        content: <div>
                            {res.data.map(item => <p>{item.tip}</p>)}
                        </div>,
                        onOk() {
                            return submitData({ ...params, floorPrice: true })
                        },
                        onCancel() { },
                    });
                } else {
                    submitData({ ...params })
                }
            })
        } else {
            submitData({ ...params })
        }

       



    }
    checkGoodsSku(rules, value, callback) {
        const { activityType } = this.formRef.current.getFieldsValue()
        value = this.PromotionsBox.current.state.goodsSku
        this.setState({
            goodsSku: value
        })
        let flag = true, hasEmpty = true, hasJoin = true
        console.log(value);
        if (value) {
            value.forEach(item => {
                if (item[1].length == 0) {
                    flag = false
                    hasEmpty = false

                    return
                }

                if (activityType === 'FULL_GIFT' && !item[2]) {
                    flag = false
                    item[3] = false
                }
                item[1].forEach(item2 => {
                    let joinLen = item2.skuInfoVos.length
                    item2.skuInfoVos.forEach(item3 => {
                        // 验证是否存在参加活动的sku
                        if (!item3.isJoinFlag) {
                            joinLen -= 1
                        }
                        // 验证是否添加活动价格
                        if ((!item3.hasOwnProperty('activityPrice') || item3.activityPrice === null || item3.activityPrice === '') && item3.isJoinFlag) {
                            flag = false
                            item3.flag = false
                        } else {
                            item3.flag = true

                        }
                        // 满赠活动类型验证商品别名是否添加
                        if (activityType === 'FULL_GIFT' && (!item3.hasOwnProperty('aliasName') || !item3.aliasName) && item3.isJoinFlag) {

                            flag = false
                            item3.aliasFlag = false
                        } else {
                            item3.aliasFlag = true
                        }
                    })
                    if (joinLen === 0) {
                        hasJoin = false
                        item2.hasJoinSku = false
                    } else {
                        item2.hasJoinSku = true

                    }

                })
            })
            this.setState({
                goodsSku: value,
                goodsFlag: flag && hasJoin,
                checkIng: true
            })
        }

        if ((value && value.length > 0 && flag)) {

            callback()
        } else {

            if (!hasEmpty) {
                callback()
                return
            }
            if (!hasJoin) {

                return Promise.resolve();
            }
            if (!flag) {

                return Promise.resolve();
            }

            callback('请添加活动商品！')
        }
    }
    getBlackGoods = (e) => {
        this.setState({ blackGoodsKey: e })
        this.formRef.current.setFieldsValue({
            blackGoods: e
        })
    }
    addGoods(e) {
        const { activityType } = this.formRef.current.getFieldsValue()

        let whiteKey = []
        e.goodsSku.forEach(item => {
            item[1].forEach(goods => {
                whiteKey.push(goods.goodsId)

                if (activityType === 'FULL_GIFT') {
                    goods.skuInfoVos.forEach(ss => {
                        if (ss.isJoinFlag) {
                            ss.activityPrice = 0
                        }
                    })
                }
            })
        })

        this.setState({
            whiteGoodsKey: whiteKey,
            goodsSku: e.goodsSku
        })
        this.formRef.current.setFieldsValue({
            goodsSku: e.goodsSku
        })
    }
    addCoupons(e) {
        console.log(e, 'addCoupons');
        this.setState({ coupons: e.coupons })
        this.formRef.current.setFieldsValue({
            coupons: e.coupons,
        })
    }
    getFileResult = (value, key) => {
        if (value.length > 0 && value[0].hasOwnProperty('response') && value[0].response) {
            this.formRef.current.setFieldsValue({
                [key]: value[0].response.data
            })
        } else {
            this.formRef.current.setFieldsValue({
                [key]: ''
            })
        }
    };
    disabledDate(current) {
        return current && current < dayjs().startOf('D');
    };
    handleOk = async () => {
        let { saveData } = this.state
        let res = await apiPlatformActivitySheetEdit({ ...saveData, repetitionPrice: true })
        if (res.code === 0 && res.data) {
            this.setState({
                visible: false
            }, () => {
                this.props.history.goBack(-1)
            })
        }
    }
    handleCancel = () => {
        this.setState({
            visible: false
        })
    }
    render() {
        let { options, goodsSku, detailImg, activityLabelImg, whiteGoodsKey, blackGoodsKey, blackGoods, levelOption, couponEnabled, timeType, sights, activityImg, optionType, optionWay, checkIng, coupons, visible, clashData } = this.state
        return (

            <div className="p-layout-box" >
                <GoBack history={this.props.history} title="编辑活动" />
                <Form
                    style={{ marginTop: 20 }}
                    ref={this.formRef}
                    initialValues={{
                        activityType: '',
                        sights: sights
                    }}
                    labelCol={{
                        span: 2,
                    }}
                    wrapperCol={{
                        span: 22,
                    }}

                    onFinish={(values) => this.onFinish(values)}
                    autoComplete="off"
                >
                    <Form.Item
                        label="活动名称"
                        name="activityName"
                        rules={[
                            {
                                required: true,
                                message: '请输入活动名称!',
                            },
                        ]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="活动类型"
                        name="activityType"
                        rules={[
                            {
                                required: true,
                                message: '请选择活动类型!',
                            }
                        ]}
                    >
                        <Select disabled style={{ width: 140 }} options={optionType} placeholder={"请选择活动类型"} />
                    </Form.Item>
                    <Form.Item
                        noStyle
                        shouldUpdate={(prevValues, currentValues) => prevValues.activityType !== currentValues.activityType}
                    >
                        {
                            ({ getFieldValue }) =>
                                ['COUPONS'].includes(getFieldValue('activityType')) ? (
                                    <Form.Item
                                        label="获取方式"
                                        name="activityWay"
                                        rules={[
                                            {
                                                required: true,
                                                message: '请选择获取方式!',
                                            },
                                        ]}
                                    >
                                        <Select disabled style={{ width: 140 }} options={optionWay} placeholder={"请选择活动类型"} />
                                    </Form.Item>

                                ) : null
                        }
                    </Form.Item>
                    <Form.Item
                        label="定时任务"
                        name="timeType"
                        rules={[
                            {
                                required: true,
                                message: '请选择是否开启定时任务!',
                            },
                        ]}
                        valuePropName={timeType} key={timeType}
                    >
                        <Switch defaultChecked={timeType} />
                    </Form.Item>
                    <Form.Item
                        label="活动等级"
                        name="activityLevel"
                        rules={[
                            {
                                required: true,
                                message: '请选择活动等级!',
                            },
                        ]}
                    >
                        <Select style={{ width: 140 }} options={levelOption} placeholder={"请选择活动等级"} />
                    </Form.Item>
                    <Form.Item
                        noStyle
                        shouldUpdate={(prevValues, currentValues) => prevValues.timeType !== currentValues.timeType}
                    >
                        {
                            ({ getFieldValue }) =>
                                getFieldValue('timeType') ?
                                    <>
                                        <Form.Item
                                            label="活动时间"
                                            name="activityTime"
                                            rules={[
                                                {
                                                    required: true,
                                                    message: '请选择活动时间!',
                                                },
                                            ]}
                                        >
                                            <RangePicker
                                                disabledDate={this.disabledDate}
                                                format="YYYY-MM-DD HH:mm:ss" style={{
                                                    width: 400,
                                                }} showTime />
                                        </Form.Item>
                                    </> : null
                        }
                    </Form.Item>

                    <Form.Item
                        label="活动详情说明"
                        name="detailExplain"
                        rules={[
                            {
                                required: true,
                                message: '请填写活动详情说明!',
                            },
                        ]}
                    >
                        <TextArea showCount
                            maxLength={100} />
                    </Form.Item>

                    <Form.Item
                        noStyle
                        shouldUpdate={(prevValues, currentValues) => prevValues.activityType !== currentValues.activityType}
                    >
                        {
                            ({ getFieldValue }) =>
                                ['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT', ''].includes(getFieldValue('activityType')) ? (

                                    <Form.Item
                                        label={getFieldValue('activityType') == 'FULL_GIFT' ? '满赠' : "优惠商品"}
                                        name="goodsSku"
                                        rules={[
                                            {
                                                required: true,
                                                validator: this.checkGoodsSku.bind(this)
                                            }
                                        ]}
                                    >
                                        <Goods checkIng={checkIng} blackGoodsKey={blackGoodsKey} mode={'add'} activityType={getFieldValue('activityType')} ref={this.PromotionsBox} goodsSku={goodsSku} addGoods={this.addGoods.bind(this)} />
                                    </Form.Item>

                                ) : ['COUPONS'].includes(getFieldValue('activityType')) ?

                                    <Form.Item
                                        label="优惠券"
                                        name="coupons"
                                    >
                                        <Coupons coupons={coupons} addCoupons={this.addCoupons.bind(this)} ref={this.couponsBox} style={{ width: 1040 }} />
                                    </Form.Item>
                                    : ['FULL_REDUCTION'].includes(getFieldValue('activityType')) ? <div>
                                        <Form.Item
                                            rules={[
                                                {
                                                    required: true,
                                                    message: '请添加满减规则'
                                                }
                                            ]}
                                            name="sights"
                                            label="满减"
                                        >
                                            <Form.List name="sights" >
                                                {(fields, { add, remove }) => (
                                                    <>
                                                        {fields.map((field) => (
                                                            <Space key={field.key} align="baseline" >
                                                                <Form.Item
                                                                    noStyle
                                                                    shouldUpdate={(prevValues, curValues) =>
                                                                        prevValues.sights !== curValues.sights
                                                                    }

                                                                >
                                                                    {() => (
                                                                        <Form.Item
                                                                            style={{ marginRight: 40 }}
                                                                            {...field}
                                                                            name={[field.name, 'thresholdPrice']}
                                                                            rules={[
                                                                                {
                                                                                    required: true,
                                                                                    message: '请填写金额',
                                                                                },
                                                                            ]}
                                                                        >
                                                                            {/* <div style={{ display: 'flex', width: 150, alignItems: 'center' }}><InputNumber precision={2} step={1} min={0} placeholder='满金额' /> &nbsp;&nbsp;<span style={{ width: 40 }}>元减</span></div> */}

                                                                            <InputNumber className="thresholdPrice" precision={2} step={1} min={0} placeholder='满金额' />
                                                                        </Form.Item>
                                                                    )}
                                                                </Form.Item>
                                                                <Form.Item
                                                                    {...field}
                                                                    name={[field.name, 'discountPrice']}
                                                                    style={{ marginRight: 40 }}

                                                                    rules={[
                                                                        {
                                                                            required: true,
                                                                            message: '请填写金额',
                                                                        },
                                                                    ]}
                                                                >
                                                                    <InputNumber className="discountPrice" precision={2} step={1} min={0} placeholder='减金额' />
                                                                </Form.Item>
                                                                <MinusCircleOutlined onClick={() => remove(field.name)} />
                                                            </Space>
                                                        ))}
                                                        <Form.Item>
                                                            <Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}>
                                                                添 加 一 条
                                                            </Button>
                                                        </Form.Item>
                                                    </>
                                                )}
                                            </Form.List>
                                        </Form.Item>
                                    </div> : null
                        }
                    </Form.Item>

                    <Form.Item
                        noStyle
                        shouldUpdate={(prevValues, currentValues) => prevValues.activityType !== currentValues.activityType}
                    >
                        {
                            ({ getFieldValue }) =>
                                ['SHOP_GOODS', ''].includes(getFieldValue('activityType')) ?
                                    <>
                                        <Form.Item
                                            label="是否用券"
                                            name="couponEnabled"
                                            rules={[
                                                {
                                                    required: true,
                                                    message: '请选择是否用券!',
                                                },
                                            ]}
                                            valuePropName={couponEnabled} key={couponEnabled}
                                        >
                                            <Switch defaultChecked={couponEnabled} />
                                        </Form.Item>

                                    </> : null

                        }
                    </Form.Item>
                    <Form.Item
                        noStyle
                        shouldUpdate={(prevValues, currentValues) => prevValues.activityType !== currentValues.activityType}
                    >
                        {
                            ({ getFieldValue }) => ['FULL_REDUCTION'].includes(getFieldValue('activityType')) ?
                                <Form.Item
                                    name="blackGoods"
                                    label="不可参与商品"
                                >
                                    <NoCanJoinGood whiteGoodsKey={whiteGoodsKey} blackGoodsKey={blackGoodsKey} blackGoods={blackGoods} getBlackGoods={this.getBlackGoods}></NoCanJoinGood>
                                </Form.Item>
                                : null
                        }

                    </Form.Item>
                    <Form.Item
                        label="活动图片"
                        name="activityImg"

                    >
                        {
                            activityImg.length > 0 &&
                            <TheUpload isConversion={false} maxSize={10} fileList={activityImg} getFileResult={(e) => this.getFileResult(e, 'activityImg')} len={1} />
                        }
                        {activityImg.length == 0 && <TheUpload isConversion={false} maxSize={10} fileList={[]} getFileResult={(e) => this.getFileResult(e, 'activityImg')} len={1} />
                        }
                    </Form.Item>
                    {/* <Form.Item
                        label="活动标签"
                        name="activityLabelImg"
                    >
                        {
                            activityLabelImg.length > 0 &&
                            <TheUpload fileList={activityLabelImg} getFileResult={(e) => this.getFileResult(e, 'activityLabelImg')} len={1} />
                        }
                        {activityLabelImg.length == 0 && <TheUpload fileList={[]} getFileResult={(e) => this.getFileResult(e, 'activityLabelImg')} len={1} />
                        }
                    </Form.Item> */}
                    <Form.Item
                        label="详情图片"
                        name="detailImg"
                    >
                        {

                            detailImg.length > 0 &&
                            <TheUpload fileList={detailImg} maxSize={10} getFileResult={(e) => this.getFileResult(e, 'detailImg')} len={1} />
                        }
                        {detailImg.length == 0 && <TheUpload fileList={[]} maxSize={10} getFileResult={(e) => this.getFileResult(e, 'detailImg')} len={1} />
                        }
                    </Form.Item>
                    <Form.Item
                        wrapperCol={{
                            offset: 8,
                            span: 16,
                        }}
                    >
                        <Button type="default" onClick={() => this.props.history.go(-1)} style={{ 'marginRight': 20 }}>
                            取消
                        </Button>
                        <Button type="primary" htmlType="submit">
                            确定
                        </Button>
                    </Form.Item>
                </Form>
                <Modal
                    visible={visible}
                    title="提示"
                    onOk={() => this.handleOk()}
                    onCancel={() => this.handleCancel()}
                    width="60%"
                >
                    {clashData &&
                        <List dataSource={clashData}
                            renderItem={item => {
                                return <List.Item>
                                    <div>
                                        商品id {item.goodsId}+{item.materialName}已存在一个{item.activityStatus === 0 ? '开启' : '关闭'}的活动【{item.activityName}】中！
                                    </div>
                                </List.Item>
                            }}
                        />
                    }
                    <br />
                    <div>
                        同一个时间段商品只能存在一个价格、优惠券使用状态，是否选择覆盖以上商品在其他特惠活动/新人活动中的价格、优惠券使用状态？
                    </div>
                </Modal>
            </div>
        )
    }
}
export default ActivityEdit
